﻿using System;
using System.Collections.Generic;
using RN.ERP.BLL;
using Fly.FlyCommon;
using RN.ERP.DTO;
using Newtonsoft.Json;
using System.ServiceModel.Activation;

namespace RN.ERP
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“AuthorityService”。
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class AuthorityService : IAuthorityService
    {
        private BaseAuthorityBLL basicBll = (BaseAuthorityBLL)BllFactory.CreateBll(BLL.BllType.Authority, Utilities.GetDbType());
        public string GetRoles(string title, string code, string areacode, string description)
        {
            return JsonConvert.SerializeObject(basicBll.GetRoles(title, code, areacode, description));
        }
        public string GetRoleByGuId(Guid guid)
        {
            return JsonConvert.SerializeObject(basicBll.GetRoleByGuId(guid));
        }
        public string AddRole(DTO.T_Sys_Roles role)
        {
            return JsonConvert.SerializeObject(basicBll.AddRole(role));
        }
        public string UpdateRole(DTO.T_Sys_Roles roleDTO)
        {
            return JsonConvert.SerializeObject(basicBll.UpdateRole(roleDTO));
        }
        public string UpdateFunction(DTO.T_Sys_Function function)
        {
            return JsonConvert.SerializeObject(basicBll.UpdateFunction(function));
        }
        public string GetFunctionList(DTO.FuncQueryCondition condition)
        {
            return JsonConvert.SerializeObject(basicBll.GetFunctionList(condition));
        }
        public string DeleteFunction(Guid funcGuid)
        {
            return JsonConvert.SerializeObject(basicBll.DeleteFunction(funcGuid));
        }
        public string AddFunction(DTO.T_Sys_Function function)
        {
            return JsonConvert.SerializeObject(basicBll.AddFunction(function));
        }
        public string GetFunctionByGuid(Guid funcGuid)
        {
            return JsonConvert.SerializeObject(basicBll.GetFunctionByGuid(funcGuid));
        }
        public string GetMenuList(Guid userGuid, string appID)
        {
            return JsonConvert.SerializeObject(basicBll.GetMenuList(userGuid, appID));
        }
        public string GetConFunctionList(Guid funcGuid)
        {
            return JsonConvert.SerializeObject(basicBll.GetConFunctionList(funcGuid));
        }
        public string OperateConFunction(Guid funcGuid, Guid conGuid, DTO.OperationType type)
        {
            return JsonConvert.SerializeObject(basicBll.OperateConFunction(funcGuid, conGuid, type));
        }
        public string AddConFunction(DTO.T_Sys_ControlFunction conFuncDTO)
        {
            return JsonConvert.SerializeObject(basicBll.AddConFunction(conFuncDTO));
        }
        public string DeleteRole(string roleGuid)
        {
            return JsonConvert.SerializeObject(basicBll.DeleteRole(roleGuid));
        }
        public string GetUserListByRoleGuid(Guid roleGuid)
        {
            return JsonConvert.SerializeObject(basicBll.GetUserListByRoleGuid(roleGuid));
        }
        public string DeleteByUserRole(string roleGuid, string userGuid)
        {
            return JsonConvert.SerializeObject(basicBll.DeleteByUserRole(roleGuid, userGuid));
        }
        public string GetUserRoleByUserRole(string roleGuid, string userGuid, string userID)
        {
            return JsonConvert.SerializeObject(basicBll.GetUserRoleByUserRole(roleGuid, userGuid, userID));
        }
        public string GetUserRolesByRoleGuid(Guid roleGuid)
        {
            return JsonConvert.SerializeObject(basicBll.GetUserRolesByRoleGuid(roleGuid));
        }
        public string GetFuncByFuncObj(string objGuid, string funcGuid, string userID)
        {
            return JsonConvert.SerializeObject(basicBll.GetFuncByFuncObj(objGuid, funcGuid, userID));
        }

        public string SetUserRole(Guid userGuid, string roleNum, string roleArea)
        {
            return JsonConvert.SerializeObject(basicBll.SetUserRole(userGuid, roleNum, roleArea));
        }

        #region 用户角色 作者：孙正滨
        //获取用户列表(绑定到下拉菜单)
        public string GetUserList(string corpName, string username)
        {
            return JsonConvert.SerializeObject(basicBll.GetUserList(corpName, username));
        }
        //获取用户角色
        public string GetUserRoles(Guid userGuid)
        {
            return JsonConvert.SerializeObject(basicBll.GetUserRoles(userGuid));
        }
        //获取用户角色
        public string GetUserRolesList(Guid userGuid, Guid roleGuid)
        {
            return JsonConvert.SerializeObject(basicBll.GetUserRolesList(userGuid, roleGuid));
        }
        //根据用户角色ID获取记录
        public string GetUserRoleById(int id)
        {
            return JsonConvert.SerializeObject(basicBll.GetUserRoleById(id));
        }
        //根据用户角色Guid获取用户角色信息
        public string GetUserRoleByGuId(Guid roleGuid)
        {
            return JsonConvert.SerializeObject(basicBll.GetUserRoleByGuId(roleGuid));
        }
        //给用户分配角色
        public string AddUserRole(DTO.T_Sys_UserRole userRoleDTO)
        {
            return JsonConvert.SerializeObject(basicBll.AddUserRole(userRoleDTO));
        }
        //修改用户角色信息
        public string UpdateUserRole(DTO.T_Sys_UserRole userRoleDTO)
        {
            return JsonConvert.SerializeObject(basicBll.UpdateUserRole(userRoleDTO));
        }
        //删除用户角色
        public string DeleteUserRole(string roleGuid, string userGuid)
        {
            return JsonConvert.SerializeObject(basicBll.DeleteUserRole(roleGuid, userGuid));
        }
        #endregion

        public string AddFuncPermission(DTO.T_Sys_FuncPermission funcDTO)
        {
            return JsonConvert.SerializeObject(basicBll.AddFuncPermission(funcDTO));
        }
        public string DelFuncPermission(Guid funcGuid, Guid objGuid)
        {
            return JsonConvert.SerializeObject(basicBll.DelFuncPermission(funcGuid, objGuid));
        }
        public string GetFuncPermission(Guid guid, string appid)
        {
            return JsonConvert.SerializeObject(basicBll.GetFuncPermission(guid, appid));
        }
        public string GetControls(string title, string method, string clientlMethod, string description)
        {
            return JsonConvert.SerializeObject(basicBll.GetControls(title, method, clientlMethod, description));
        }
        public string GetControlByGuId(Guid guid)
        {
            return JsonConvert.SerializeObject(basicBll.GetControlByGuId(guid));
        }
        public string GetControlByFunGuid(Guid funguid)
        {
            return JsonConvert.SerializeObject(basicBll.GetControlByFunGuid(funguid));
        }
        public string AddControl(DTO.T_Sys_Control controlDTO)
        {
            return JsonConvert.SerializeObject(basicBll.AddControl(controlDTO));
        }
        public string UpdateControl(DTO.T_Sys_Control controlDTO)
        {
            return JsonConvert.SerializeObject(basicBll.UpdateControl(controlDTO));
        }
        public string DeleteControl(string controlGuid)
        {
            return JsonConvert.SerializeObject(basicBll.DeleteControl(controlGuid));
        }
        public string GetFunction()
        {
            return JsonConvert.SerializeObject(basicBll.GetFunction());
        }

        #region 用户添加功能 作者：孙正滨
        public string CheckFuncByUserGuid(string objGuid, string funcGuid)
        {
            return JsonConvert.SerializeObject(basicBll.CheckFuncByUserGuid(objGuid, funcGuid));
        }

        public string GetFuncListByUserGuid(Guid objGuid)
        {
            return JsonConvert.SerializeObject(basicBll.GetFuncListByUserGuid(objGuid));
        }

        public string ChechFuncByFuncObj(string objGuid, string funcGuid, string userID)
        {
            return JsonConvert.SerializeObject(basicBll.ChechFuncByFuncObj(objGuid, funcGuid, userID));
        }
        #endregion

        #region UC控件调用
        public List<DTO.tb_Emp_TitleClass> GetPsnQualLevelByType(int nid)
        {
            return null;
        }
        #endregion UC控件调用

        public int GetUserCount(string corpName)
        {
            return basicBll.GetUserCount(corpName);
        }

        public string CheckPermission(string funcGuid, string objGuid, int funcType, int type, bool ischeck)
        {
            return JsonConvert.SerializeObject(basicBll.CheckPermission(funcGuid, objGuid, funcType, type, ischeck));
        }

        public string GetUserFunctions(string userGuid, string functionGuid, string appId)
        {
            return JsonConvert.SerializeObject(basicBll.GetUserFunctions(userGuid, functionGuid, appId));
        }

        public string GetUserControls(string userGuid, string functionGuid, string appId)
        {
            return JsonConvert.SerializeObject(basicBll.GetUserControls(userGuid, functionGuid, appId));
        }

        public string GetUserMenus(string userGuid, string functionGuid, string appId)
        {
            return JsonConvert.SerializeObject(basicBll.GetUserMenus(userGuid, functionGuid, appId));
        }

        public string GetUserFuncCodes(string userGuid, bool isMenu, string appId)
        {
            return JsonConvert.SerializeObject(basicBll.GetUserFuncCodes(userGuid, isMenu, appId));
        }

        public string GetRoleFunctions(string roleGuid, string functionGuid, string appId)
        {
            return JsonConvert.SerializeObject(basicBll.GetRoleFunctions(roleGuid, functionGuid, appId));
        }



        public string GetSysApp()
        {
            return JsonConvert.SerializeObject(basicBll.GetSysApp());
        }

        public string GetUserSysPermission(string userGuid, int type)
        {
            return JsonConvert.SerializeObject(basicBll.GetUserSysPermission(userGuid, type));
        }

        public string UpdatePermission(DTO.T_Sys_FuncPermission funcDTO)
        {
            return JsonConvert.SerializeObject(basicBll.UpdatePermission(funcDTO));
        }

        public string GetFuncPermissionForUser(Guid roleGuid, Guid userGuid, string appid)
        {
            return JsonConvert.SerializeObject(basicBll.GetFuncPermissionForUser(userGuid, appid));
        }

        public string SaveorUpdateFuncPermissionForUser(Guid roleGuid, Guid userGuid, string appid, List<string> addFuncs)
        {
            return JsonConvert.SerializeObject(basicBll.SaveorUpdateFuncPermissionForUser(userGuid, appid, addFuncs));
        }

        public string AddPageMapping(DTO.FuncPageMapping page)
        {
            return JsonConvert.SerializeObject(basicBll.AddPageMapping(page));
        }


        #region 部门管理

        public string GetDepartmentData(string AreaCode)
        {
            return JsonConvert.SerializeObject(basicBll.GetDepartmentData(AreaCode));
        }

        public string AddDepartment(DTO.dict_Department dept)
        {
            return JsonConvert.SerializeObject(basicBll.AddDepartment(dept));
        }

        public string UpdateDepartment(DTO.dict_Department dept)
        {
            return JsonConvert.SerializeObject(basicBll.UpdateDepartment(dept));
        }

        public string DeleteDepartment(int id)
        {
            return JsonConvert.SerializeObject(basicBll.DeleteDepartment(id));
        }

        #endregion

    }
}
